import { post } from "../../../utils/request";

// 获取推送场景下拉框狂
const getSceneList = () => post("/push/getPushSceneName");
// 获取推送应用下拉框
const getPushApp = () => post("/push/getPushApp");
// 获取推送方式下拉框
const getPushWay = () => post("/push/getPushWay");
// 获取触发动作下拉框
const getTrigger = appId => post("/push/getTrigger", { appId: String(appId) });
// 获取推送对象类型下拉框
const getPushObjType = () => post("/push/getPushObjType");

/** 获取推送计划表格
 *
 * @param {Number} pageIndex
 * @param {Number} pageSize
 * @param {String} order
 * @param {String} status
 * @param {String} comments
 */
const getPlanTable = ({
  pageIndex = 1,
  pageSize = 10,
  order = "",
  status = "",
  planName = ""
}) =>
  post("/push/pushPlanConfigQuery", {
    pageIndex: String(pageIndex),
    pageSize: String(pageSize),
    order,
    status,
    planName
  });

/** 获取推送计划详情
 *
 * @param {String} planId
 */
const getPlanDetail = ({ id }) =>
  post("/push/pushPlanDetailQuery", { id: String(id) });

/**
 *
 * @param {}
 */
const addPlan = ({
  id,
  planName,
  sceneId,
  appId,
  objectAppId,
  pushType,
  opTypeCode = null,
  timeType = null,
  pushTimes = null,
  timesUnit = null,
  pushObjectType = null,
  pushObject = null,
  pushObjectDesc = null,
  comments = null,
  periodType = null,
  effTime = null,
  expTime = null
}) =>
  post("/push/pushPlanConfigAdd", {
    id: id ? String(id) : null,
    planName,
    sceneId,
    appId: Number(appId),
    objectAppId: Number(objectAppId),
    pushType,
    opTypeCode,
    timeType,
    pushTimes,
    timesUnit,
    pushObjectType,
    pushObject: pushObject || null,
    pushObjectDesc,
    comments,
    periodType,
    effTime,
    expTime
  });

/** 删除推送计划
 *
 * @param {String} id
 */
const deletePlan = ({ id }) =>
  post("/push/pushPlanConfigDelete", { id: String(id) });

/** 启用/ 停用推送计划
 *
 * @param {String} id
 */
const updateStatus = ({ id, isStatus }) =>
  post("/push/updatePlanStatus", { id: String(id), isStatus });

// 查询组织
const getOrg = () => post("/push/getRootTree");

export default {
  getSceneList,
  getPushApp,
  getPushWay,
  getTrigger,
  getPushObjType,
  getPlanTable,
  getPlanDetail,
  addPlan,
  deletePlan,
  updateStatus,
  getOrg
};
